<template>
  <div>
    <zeda-dialog
      v-model="visible"
      width="600px"
      title="审核"
      :before-close="handleClose"
    >
      <Title name="基本信息" :line="false" slot="green">
        <desc-base-info
          :data="info"
          :colnum-info="baseInfo"
          align="right"
          :no-line-height="true"
          label-width="120px"
          class="base-info"
        >
          <template slot="setStatus">
            <dict-tag :options="dict.type.set_status" :value="info.setStatus" />
          </template>
        </desc-base-info>
      </Title>
      <form-button
        slot="footer"
        :show-submit-button="false"
        @cancel="handleClose"
      >
        <template>
          <el-button
            v-if="info.setStatus == 81 || info.setStatus == 82"
            type="warning"
            size="small"
            @click="submit(0)"
            >驳回</el-button
          >
          <el-button
            v-if="info.setStatus == 81 || info.setStatus == 82"
            type="primary"
            size="small"
            @click="submit(1)"
            >审批</el-button
          >
          <el-button
            v-if="info.setStatus == 80"
            type="primary"
            size="small"
            @click="submit(2)"
            >下发</el-button
          >
        </template></form-button
      >
    </zeda-dialog>
  </div>
</template>
    <script>
import { detail, audit, reject, plugset } from "@/api/iot/upgrade";
import Title from "@/components/Title";
import FormButton from "@/components/FormButton";

export default {
  dicts: ["set_status"],
  components: {
    Title,
    FormButton,
  },
  props: {
    visible: { type: Boolean, default: false },
    id: { type: [String, Number], default: "" },
  },
  data() {
    return {
      info: {},
    };
  },

  computed: {
    baseInfo({ info }) {
      let arr = [
        { label: "修改前设备编码", prop: "deviceCode", colNum: 2 },
        { label: "修改后设备编码", prop: "newDeviceCode", colNum: 2 },
        { label: "预警功率", prop: "networkName", colNum: 2, unit: "w" },
        { label: "远程连接IP", prop: "ip", colNum: 2 },
        { label: "远程连接端口", prop: "port", colNum: 2 },
        {
          label: "定时上传时间",
          prop: "uploadInterval",
          colNum: 2,
          unit: "分钟",
        },
        { label: "参数件版本名称", prop: "fileName", colNum: 2 },
        { label: "参数件版本号", prop: "versionCode", colNum: 2 },
        { label: "参数最新升级时间", prop: "ratedCurrent", colNum: 2 },
        { label: "状态", prop: "setStatus", colNum: 2 },
      ];
      return arr;
    },
  },
  watch: {
    visible(value) {
      if (value && String(this.id).length > 0) {
        this.getInfo();
      }
    },
  },
  methods: {
    getInfo() {
      const that = this;
      detail(that.id)
        .then((res) => {
          if (res.code === 700) {
            that.$message.warning(res.msg);
            return false;
          }

          that.info = res.data;
        })
        .catch((err) => {
          that.info = {};
          // this.$message.error("系统错误,请联系管理员!300906");
        });
    },
    submit(type) {
      let query = {};
      query.plugSetAuditRequestList = [{ id: this.info.id, auditStatus: type }];
      let text =
        type === 0 ? "驳回" : type === 1 ? "审批" : type === 2 ? "下发" : "";
      this.$confirm(`是否确认进行${text}？`, "提示", {
        type: "warning",
      })
        .then(() => {
          if (type === 0) {
            reject(query)
              .then((res) => {
                if (res.code === 700) {
                  this.$message.warning(res.msg);
                  return false;
                }
                this.$message.success("操作成功");
                this.handleClose(true);
              })
              .catch(() => {
                // this.$message.error("系统错误,请联系管理员!300708");
              });
          } else if (type === 1) {
            audit(query)
              .then((res) => {
                if (res.code === 700) {
                  this.$message.warning(res.msg);
                  return false;
                }
                this.$message.success("操作成功");
                this.handleClose(true);
              })
              .catch(() => {
                // this.$message.error("系统错误,请联系管理员!300707");
              });
          } else {
            plugset(query)
              .then((res) => {
                if (res.code === 709) {
                  this.$message.warning(res.msg);
                  return false;
                }
                this.$message.success("操作成功");
                this.handleClose(true);
              })
              .catch(() => {
                // this.$message.error("系统错误,请联系管理员!300709");
              });
          }
        })
        .catch(() => {});
    },
    handleClose(status) {
      this.$emit("update:visible", false);
      this.$emit("close", typeof status === "boolean" ? status : false);
    },
  },
};
</script>

  <style lang="scss" scoped>
@import "@/assets/styles/mixin.scss";
::v-deep .el-dialog__body {
  @include scrollBar2;
  .title-container {
    padding: 20px 0;
  }
}
</style>
